<template>
  <div>
    <el-dialog :visible.sync="AssigneeDialogVisible" title="选择指派人员">
      <el-form :v-model="node" label-position="left" lebel-width="120px">
        <el-form-item label="选择指派人">
          <DeptUserS ref="DeptUserS" @select="handleSelected" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="AssigneeDialogVisible = false">取 消</el-button>
        <el-button type="primary" :loading="btnLoading" @click="handleAssigneeSubmit">确定指派</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import DeptUserS from '@/components/DeptUserS'
import { appoint } from '@/api/workflow/bpmn/runtime'
export default {
  components: {
    DeptUserS // 部门人员选择框
  },
  props: ['taskId'],
  data() {
    return {
      AssigneeDialogVisible: false,
      btnLoading: false,
      node: {}
    }
  },
  computed: {
  },
  created() {
    
  },
  methods: {
    handleSelected(node) { // 选择部门岗位人员回调
      this.node = node
    },
    handleAssigneeSubmit() { // 提交指派
      if (!this.node || !this.node.id) {
        this.$message.error('请选择指派人员')
        return
      }
      const ids = this.node.id.split('-')
      if (!(ids.length >= 2)) {
        this.$message.error('请选择指派人员')
        return
      }
      const deptId = ids[0]
      const userId = ids[1]
      const currentUserId = this.$store.getters.userInfo ? this.$store.getters.userInfo.userId : ''
      
      const post = {
        deptId: deptId,
        // positionId: this.node.positionId,
        taskId: this.taskId,
        currentUserId: currentUserId, // 指派人
        userId: userId // 被指派人
      }
      this.btnLoading = true
      appoint(post).then(res => {
        this.btnLoading = false
        this.AssigneeDialogVisible = false
        this.$message.success('指派成功')
        this.$router.push({ path: '/workflow/bpmn/task' })
      })
    }
  }
}
</script>

<style scoped>
  .tree-box {
    height: 200px;
    overflow: auto;
  }
</style>
